{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "wired-forty",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\u001b[36mres1\u001b[39m: \u001b[32mInt\u001b[39m = \u001b[32m11\u001b[39m"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "10.+(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "numeric-halifax",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\u001b[36mres2\u001b[39m: \u001b[32mInt\u001b[39m = \u001b[32m11\u001b[39m"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "10 +1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "ceramic-oliver",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.0\n",
      "3.0\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "defined \u001b[32mclass\u001b[39m \u001b[36mVec\u001b[39m\r\n",
       "\u001b[36mvector1\u001b[39m: \u001b[32mVec\u001b[39m = \u001b[33mVec\u001b[39m(\u001b[32m1.0\u001b[39m, \u001b[32m1.0\u001b[39m)\r\n",
       "\u001b[36mvector2\u001b[39m: \u001b[32mVec\u001b[39m = \u001b[33mVec\u001b[39m(\u001b[32m2.0\u001b[39m, \u001b[32m2.0\u001b[39m)\r\n",
       "\u001b[36mvector3\u001b[39m: \u001b[32mVec\u001b[39m = \u001b[33mVec\u001b[39m(\u001b[32m3.0\u001b[39m, \u001b[32m3.0\u001b[39m)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "case class Vec(x:Double,y:Double) {\n",
    "    def +(that:Vec) = Vec(this.x+that.x,this.y + that.y)\n",
    "}\n",
    "\n",
    "val vector1 = Vec(1.0,1.0)\n",
    "val vector2 = Vec(2.0,2.0)\n",
    "\n",
    "val vector3 = vector1 + vector2\n",
    "\n",
    "println(vector3.x)\n",
    "println(vector3.y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "generous-proportion",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "defined \u001b[32mclass\u001b[39m \u001b[36mMyBool\u001b[39m"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "case class MyBool(x:Boolean) {\n",
    "    def and(that :MyBool): MyBool = if(x)that else this\n",
    "    def or(that:MyBool): MyBool = if(x)this else that\n",
    "    def negate:MyBool = MyBool(!x)\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "mathematical-inventory",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "defined \u001b[32mfunction\u001b[39m \u001b[36mnot\u001b[39m\r\n",
       "defined \u001b[32mfunction\u001b[39m \u001b[36mxor\u001b[39m"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def not(x:MyBool) = x.negate\n",
    "def xor(x:MyBool,y:MyBool) = (x or y) and not(x and y)//异或"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "biological-russia",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\u001b[36ma\u001b[39m: \u001b[32mMyBool\u001b[39m = \u001b[33mMyBool\u001b[39m(true)\r\n",
       "\u001b[36mb\u001b[39m: \u001b[32mMyBool\u001b[39m = \u001b[33mMyBool\u001b[39m(false)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val a = MyBool(true)\n",
    "val b = MyBool(false)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "stylish-aerospace",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\u001b[36mc\u001b[39m: \u001b[32mMyBool\u001b[39m = \u001b[33mMyBool\u001b[39m(true)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val c = xor(a,b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "tired-essence",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\u001b[36ma\u001b[39m: \u001b[32mInt\u001b[39m = \u001b[32m10\u001b[39m\r\n",
       "\u001b[36mb\u001b[39m: \u001b[32mInt\u001b[39m = \u001b[32m20\u001b[39m\r\n",
       "\u001b[36mc\u001b[39m: \u001b[32mInt\u001b[39m = \u001b[32m30\u001b[39m\r\n",
       "\u001b[36md\u001b[39m: \u001b[32mInt\u001b[39m = \u001b[32m40\u001b[39m"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val a = 10\n",
    "val b = 20\n",
    "val c = 30\n",
    "val d = 40"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "animated-defeat",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "cmd14.sc:1: value ^? is not a member of Int\n",
      "val e = ((a + b) ^? (c ?^ d)) less ((a ==> b) | c)\n",
      "                 ^cmd14.sc:1: value ?^ is not a member of Int\n",
      "val e = ((a + b) ^? (c ?^ d)) less ((a ==> b) | c)\n",
      "                       ^cmd14.sc:1: value ==> is not a member of Int\n",
      "val e = ((a + b) ^? (c ?^ d)) less ((a ==> b) | c)\n",
      "                                       ^Compilation Failed"
     ]
    },
    {
     "ename": "",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "Compilation Failed"
     ]
    }
   ],
   "source": [
    "val e = ((a + b) ^? (c ?^ d)) less ((a ==> b) | c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "liberal-vietnamese",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Scala",
   "language": "scala",
   "name": "scala"
  },
  "language_info": {
   "codemirror_mode": "text/x-scala",
   "file_extension": ".scala",
   "mimetype": "text/x-scala",
   "name": "scala",
   "nbconvert_exporter": "script",
   "version": "2.11.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
